
#include "stdafx.h"
#include <myClassCachePool.h>

using namespace std;
using namespace myFn;
using namespace myFn::v1;
//====================================================================================



struct Test2
{
	stdsize iKey;
	stdsize ival;

	stdsize operator()(const Test2 &a)
	{
		return a.iKey;
	}
};





typedef mySimpleClsPool<Test2>		TMemPool;
typedef myClsCachePool<TMemPool>	TCachePool;
typedef TCachePool::_TItemPtr		Test2Ptr;

TMemPool mempool;
TCachePool cachepool;



//=====================================================================================
void test_myClassCachePool()
{
	//-------------------------------
	{
		typedef mySingleLstItem<Test2>		TLstItem;
		typedef mySingleLst<TLstItem>	TLst;

		TLst slst;

		TLstItem it1;
		slst.insert_prev_head(&it1);
		TLstItem *it2 = slst.head();
		it2 = slst.erase_head();

		TLst::iterator it;
		for (it = slst.begin();it != slst.end(); ++it)
		{
			(*it).iKey = 100;
		}
	}
	{
		typedef myDblstItem<Test2>		TLstItem;
		typedef myDblst<TLstItem>	TLst;

		TLst slst;

		TLstItem it1;
		slst.insert_head(&it1,false);
		TLstItem *it2 = slst.head();
		it2 = slst.erase_head();

		TLst::riterator it;
		for (it = slst.rbegin();it != slst.rend(); ++it)
		{
			(*it).iKey = 100;
		}
	}






	//-------------------------------------
	cachepool.set(&mempool);
	Test2Ptr ptr = cachepool.NewPtr();
	ptr->iKey = 100;
	ptr->ival = 150;
	cachepool.insert(ptr);

	Test2 t2;
	t2.iKey = 101;
	t2.ival = 151;
	cachepool.insert(t2);

	Test2Ptr ptr1 = cachepool.find(100);

	cachepool.erase(ptr);

}

